"""
Case Type   : 基础功能
Case Name   : idle_in_transaction_session_timeou参数使用gs_guc reload设置为其他数据类型，设置失败，合理报错
Create At   : 2022/11/11
Owner       : haomeng802
Description :
    1.查看idle_in_transaction_session_timeout默认值
    2.使用gs_guc reload设置idle_in_transaction_session_timeout为其他数据类型
Expect      :
    1.成功
    2.合理报错
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class IdleSession(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        text = f'----{os.path.basename(__file__)} start----'
        self.log.info(text)
        self.sh_primysh = CommonSH('PrimaryDbUser')
        self.constant = Constant()

    def test_idlesession(self):
        step_text1 = "----step1：查看idle_in_transaction_session_timeout默认值；" \
               "expect：成功----"
        self.log.info(step_text1)
        self.show_sql = 'show idle_in_transaction_session_timeout;'
        self.log.info(self.show_sql)
        result_show = self.sh_primysh.execut_db_sql(self.show_sql)
        self.log.info(result_show)
        self.assertIn('0', result_show, '执行失败' + step_text1)

        step_text2 = "----step2：使用gs_guc reload设置" \
                     "idle_in_transaction_session_timeout为其他数据类型;" \
                     "expect：合理报错---"
        self.log.info(step_text2)
        result_guc = self.sh_primysh.execute_gsguc(
            "reload", self.constant.GSGUC_SUCCESS_MSG,
            f"idle_in_transaction_session_timeout= 'test'")
        self.assertFalse(result_guc)

    def tearDown(self):
        self.log.info(f'----{os.path.basename(__file__)} end----')
